package cn.zktr.Personnel.controllers.zhouyongcong.end;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerPmsFun;
import cn.zktr.Personnel.model.pojos.PerPmsPes;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.service.zhouyongcong.getUitlsService;
import cn.zktr.Personnel.model.service.zhouyongcong.end.authorityService;

@Controller
public class authorityController {
	@Autowired
	private getUitlsService gus;
	@Autowired
	private findService fs;
	@Autowired
	private authorityService as;
	
	@RequestMapping("zyc/authority-table")
	public void authority_table() {}
	
	@RequestMapping("authority_t")
	@ResponseBody
	public Map<String,Object> authority_t(Integer page,Integer rows) {
		Map<String,Object> map = new HashMap<>();
		JSONArray json = new JSONArray();
		map.put("total",fs.findAllEmp().size());
		int i=0;
		for(PerPmsEmp ppe : fs.findAllEmp()){
			if((page-1)*rows<=i&&i<page*rows&&ppe.getPerPmsStms().size()!=0) {
				JSONObject jo = new JSONObject();
	            jo.put("empname", ppe.getEmpname());
	            jo.put("position", ppe.getPerPmsStms().get(0).getPerPmsPot().getPotzw());
	            json.add(jo);
			}
            i++;
        }
		map.put("rows",json);
		
		return map;
	}
	@RequestMapping("authority_e")
	@ResponseBody
	public List<PerPmsPes> tail_1(Integer empid) {
		return as.tail_1(empid);
	}
	@RequestMapping("authority_r")
	@ResponseBody
	public List<PerPmsFun> tail_2(Integer empid,String text) {
		return as.tail_2(empid,text);
	}
	
	
	@RequestMapping("zyc/authority-pot")
	public void authority_pot(Model mod) {
		mod.addAttribute("Authority", gus.getAuthority());
	}
	
	@RequestMapping("aut_emp")
	@ResponseBody
	public void aut_emp(HttpSession session,int yid,String sf,String aut,Integer empid) {
		as.aut_emp(empid,yid, sf, aut);
	}
	@PostMapping("aut_emf")
	@ResponseBody
	public void aut_emf(int empid,int[] funid,String[] fun) {
		as.aut_emf(empid,funid,fun);
	}
}
